package com.neulogistics.core.substation.api.application.command.handler;

import com.blackto.lib.mediat.unicast.IRequestHandler;
import com.neulogistics.core.substation.api.application.command.CreateSubstationCommand;
import com.neulogistics.core.substation.api.application.command.CreateTaskOrderCommand;
import com.neulogistics.core.substation.api.application.query.ISubstationQueryService;
import com.neulogistics.core.substation.api.application.rpc.ISubstationRPC;
import com.neulogistics.core.substation.api.application.rpc.dto.OrderDTO;
import com.neulogistics.core.substation.api.application.rpc.dto.WarehouseDTO;
import com.neulogistics.core.substation.domain.model.aggregate.Substation;
import com.neulogistics.core.substation.domain.model.aggregate.TaskOrder;
import com.neulogistics.core.substation.domain.model.enumeration.TaskType;
import com.neulogistics.core.substation.domain.model.valueobject.CustomInfo;
import com.neulogistics.core.substation.domain.model.valueobject.OrderInfo;
import com.neulogistics.core.substation.domain.repository.ISubstationRepository;
import com.neulogistics.core.substation.domain.repository.ITaskOrderRepository;
import com.neulogistics.infrastructure.cache.idservice.RedisIdUtil;
import com.neulogistics.infrastructure.common.serviceresult.BaseResponse;
import com.neulogistics.infrastructure.common.serviceresult.ErrorCode;
import com.neulogistics.infrastructure.common.serviceresult.ResultUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class CreateSubstationCommandHandler implements IRequestHandler<CreateSubstationCommand, BaseResponse<String>> {
    @Resource
    ISubstationRPC substationRPC;

    @Resource
    ISubstationRepository substationRepository;

    @Override
    public BaseResponse<String> handle(CreateSubstationCommand command) {
        // 查询分站库房是否存在
//        WarehouseDTO warehouse = substationRPC.getWarehouseById(command.subWarehouseId);
//        if(warehouse == null){
//            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR, "分站库房不存在");
//        }

        // 创建分站
        Substation substation = new
                Substation(command.substationName, command.getSubstationAddress(), command.subWarehouseId);
        substationRepository.save(substation);

        return ResultUtils.success(substation.getSubstationId().toString());
    }
}
